package de.fmaul.dicheck.runner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import de.fmaul.dicheck.model.TestCase;

public class TestRunnerResult {

    private final Map<TestCase, TestResult> testResults = new LinkedHashMap<TestCase, TestResult>();
    private final Map<String, TestResult> testResultsById = new HashMap<String, TestResult>();

    public TestResult getTestResult(final TestCase testCase) {
        return testResults.get(testCase);
    }

    public List<? extends TestResult> getAllTestResults() {
        return new ArrayList<TestResult>(testResults.values());
    }

    // TODO optimize
    public TestResult getTestResultByTestName(final String name) {
        for (final TestCase t : testResults.keySet()) {
            if (t.getName().equals(name)) {
                return getTestResult(t);
            }
        }
        return null;
    }

    // TODO optimize
    public TestResult getTestResultByTestId(final String testId) {
        return testResultsById.get(testId);
    }

    public void putResult(final TestCase testCase, final TestResult testResult) {
        testResults.put(testCase, testResult);
        testResultsById.put(testCase.getId(), testResult);
    }
}
